package io.renren.modules.evaluate.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
///////归一化：线性尺度变换法
public class LinearScale {
    public static void main(String[] args){
        /*String path = "d:\\123.xls";
        int n = 2;//输入*/
        double[] b = readxls();
        System.out.println(Arrays.toString(b));
        return ;
    }

    public static double[] readxls() {
        ArrayList<String> arr = new ArrayList<>();
        arr.add("23");
        arr.add("56");
        /*File file = new File(pathname);
        try {
            readColumn(file, n);//读取指定列
            arr = readColumn(file, n);
            //System.out.println(arr);
        } catch (Exception e) {
            e.printStackTrace();
        }*/
        int m = arr.size();
        double[] doubleArray=new double[m];
        for(int i=0;i<m;i++){
            doubleArray[i]=new Double(arr.get(i));
        }
        double[] a = guiyi(doubleArray);
        return a;

    }
    /*public static ArrayList<String> readColumn(File file, int index) throws Exception {
        ArrayList<String> res = new ArrayList<>();
        InputStream inputStream = new FileInputStream(file.getAbsoluteFile());
        Workbook workbook = Workbook.getWorkbook(inputStream);
        Sheet sheet = workbook.getSheet(0);
        int rows = sheet.getRows();
        int columns = sheet.getColumns();
        for (int i = 1; i < rows; i++) {
            Cell cell = sheet.getCell(index, i);
            res.add(cell.getContents());
        }
        return res;
    }*/
    public static double[]  guiyi(double[] arr){

        int n = arr.length;
        double max = getMax(arr);
        double[] f = new double[n];
        double[] f1 = new double[n];
        for (int i=0; i<n;i++){
            double m = arr[i];
            f [i] =  m/max;
            //保留4位小数
            BigDecimal b   =   new   BigDecimal(f[i]);
            f1 [i]  =   b.setScale(4,   BigDecimal.ROUND_HALF_UP).doubleValue();
        }

        return f1;
    }

    public static double getMax(double[] arr){
        double max = arr[0];
        for (int i=0; i < arr.length;i++)
        {
            if (arr[i]>max){
                max = arr[i];
            }
        }
//       取数组最大值
        return max;
    }
}
